﻿using DomainModel;
using MusicManager.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace AzureTestClient
{
    class Client
    {
        private const string DEFAULT_MUSICMANAGER_EP = "MusicManagerService_BasicHttpEndpoint";
        private const string DEFAULT_USERMANAGER_EP = "UserManagerService_BasicHttpEndpoint";

        private static void TestMusicManagerClient()
        {
            using(ChannelFactory<IMusic> cf = new ChannelFactory<IMusic>(DEFAULT_MUSICMANAGER_EP))
            {
                Console.WriteLine("Endpoint address: {0}", cf.Endpoint.Address.Uri);

                IMusic musicProxy = cf.CreateChannel();
            }
        }

        private static void TestUserManagerClient()
        {
            using (ChannelFactory<IUser> cf = new ChannelFactory<IUser>(DEFAULT_USERMANAGER_EP))
            {
                Console.WriteLine("Endpoint address: {0}", cf.Endpoint.Address.Uri);

                IUser userProxy = cf.CreateChannel();

                IEnumerable<User> allUser = userProxy.FindAll();
                Console.WriteLine("{0} user(s) found:", allUser.Count());
                foreach (var user in allUser)
                {
                    Console.WriteLine("{0} {1} {2}", user.Name, user.Id, user.Password);
                }
            }
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Database Init()");
            //Database.Init();
            TestUserManagerClient();
            Console.ReadLine();
        }
    }
}
